package bupt.party.online.util;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.CriteriaQuery;

public class MysqlOrder extends Order {

	private static final long serialVersionUID = 6148881438891056876L;
	
	private String propertyName;
	
	protected MysqlOrder(String propertyName) {   
	   super(propertyName, false);   
	   this.propertyName = propertyName;   
	}

	/**  
	* 只考虑按一个字段排序的情况  
	*/   
	public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {   
	   String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName);   
	   return " CONVERT( "+ columns[0] +" USING GBK) ";   
	}   
	
	public static MysqlOrder getOrder(String propertyName)   
	{   
	return new MysqlOrder(propertyName);   
	}   

}
